package com.hjx.movie.core.system.controller.admin;

import com.hjx.movie.common.utils.Result;
import com.hjx.movie.common.utils.ResultType;
import com.hjx.movie.core.system.service.admin.ICinemaHallService;
import com.hjx.movie.persistence.system.model.IvyCinemaHall;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2021/2/9 - 14:49
 */
@Slf4j
@RestController
@RequestMapping("/cinemaHall")
public class CinemaHallController {
    @Resource
    ICinemaHallService cinemaHallService;


    @GetMapping("/findAll")
    public Result findAllCinemaHall(){
        return Result.success(cinemaHallService.findAllCinemaHall());
    }

    @GetMapping("/findByCondition")
    public Result findCinemaByAreaId(@RequestParam(name = "cinemaId",required = false)Long cinemaId,
                                     @RequestParam(name = "cinemaHallNameLike",required = false)String cinemaHallNameLike,
                                     @RequestParam(name = "cinemaHallStatus",required = false)Integer cinemaHallStatus){
        return Result.success(cinemaHallService.findCinemaHallByCondition(cinemaId, cinemaHallNameLike, cinemaHallStatus));
    }

    @PostMapping("/add")
    public Result addCinemaHall(@RequestBody IvyCinemaHall cinemaHall){
        if (cinemaHallService.addCinemaHall(cinemaHall)){
            return Result.success("新增影厅成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"新增影厅失败");
    }
    @GetMapping("/delete")
    public Result deleteCinemaHall(@RequestParam("cinemaHallId") Long cinemaHallId){
        if (cinemaHallService.realDeleteCinemaHall(cinemaHallId)){
            return Result.success("删除影厅成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"删除影厅失败");
    }
    @GetMapping("/logicDelete")
    public Result logicDeleteCinemaHall(@RequestParam("cinemaHallId") Long cinemaHallId){
        if (cinemaHallService.logicDeleteCinemaHall(cinemaHallId)){
            return Result.success("删除影厅成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"删除影厅失败");
    }


    @PostMapping("/update")
    public Result updateCinemaHall(@RequestBody IvyCinemaHall cinemaHall){
        if (cinemaHallService.updateCinemaHall(cinemaHall)){
            return Result.success("修改影厅成功");
        }
        return Result.error(ResultType.USER_INPUT_ERROR,"修改影厅失败");
    }

}
